/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package multithreading.apsOrdenacao;

public class MetodosOrdenacao {

    public MetodosOrdenacao() {
    }

    public static boolean InsercaoShell(int[] vet) {
        boolean teste = false;
        int n = vet.length;
        int h = n / 2;
        int c, j;
        while (h > 0) {
            for (int i = h; i < n; i++) {
                c = vet[i];
                j = i;
                while (j >= h && vet[j - h] > c) {
                    teste = true;
                    vet[j] = vet[j - h];
                    j = j - h;
                }
                vet[j] = c;
            }
            h = h / 2;
        }
        return teste;
    }

    public static boolean Bolha(int[] vet) {
        boolean teste = false;
        for (int i = 0; i < (vet.length - 1); i++) {
            for (int j = 0; j < (vet.length - 1) - i; j++) {
                if (vet[j] > vet[j + 1]) {
                    int aux;
                    aux = vet[j];
                    vet[j] = vet[j + 1];
                    vet[j + 1] = aux;
                    teste = true;
                }
            }
        }
        return teste;
    }

    public static boolean SelecaoDireta(int[] vet) {
        boolean teste = false;
        int index_min, aux;
        for (int i = 0; i < vet.length; i++) {
            index_min = i;
            for (int j = i + 1; j < vet.length; j++) {
                if (vet[j] < vet[index_min]) {
                    index_min = j;
                }
            }
            if (index_min != i) {
                aux = vet[index_min];
                vet[index_min] = vet[i];
                vet[i] = aux;
                teste = true;
            }
        }
        return teste;
    }

    public static boolean InsercaoDireta(int[] vet) {
        boolean teste = false;
        for (int i = 1; i < vet.length; i++) {
            int a = vet[i];
            int j;
            for (j = i - 1; j >= 0 && vet[j] > a; j--) {
                vet[j + 1] = vet[j];
                vet[j] = a;
                teste = true;
            }
        }
        return teste;
    }
}
